package org.blame.rabbitmqadvancedfeature.listener;

import com.rabbitmq.client.Channel;
import org.blame.rabbitmqadvancedfeature.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
public class DelListener {

    @RabbitListener(queues = Constants.DEL_QUEUE)
    public void delMessage1(Message message){
        System.out.printf("接收到的消息:%s, deliveryTag: %d \n",new String(message.getBody(), StandardCharsets.UTF_8)
                ,message.getMessageProperties().getDeliveryTag());
    }

//    @RabbitListener(queues = Constants.NORMAL_QUEUE)
//    public void delMessage2(Message message, Channel channel) throws Exception {
//
//        System.out.printf("接收到的消息:%s, deliveryTag: %d \n",new String(message.getBody(), StandardCharsets.UTF_8)
//                ,message.getMessageProperties().getDeliveryTag());
//
//        long getDeliveryTag=message.getMessageProperties().getDeliveryTag();
//        try {
//            int num=3/0;
//            System.out.println("消息发送完成");
//            channel.basicAck(getDeliveryTag,false);
//        }catch (Exception e){
//            channel.basicNack(getDeliveryTag,false,false);
//        }
//
//    }
}
